#include "Util.hpp"
#include "Data.hpp"
#include "Server.hpp"

using namespace aod;

void FileUtilTest()
{
    std::string name = "TestFile";
    FileUtil fu(name);

    // fu.CreateDirectory();

    std::cout << fu.Exists() << std::endl;

    int ret = fu.FileSize();
    std::cout << ret << std::endl;
    std::string content;
    fu.GetContent(&content);
    std::cout << content << std::endl;
    content.clear();
    content = "11111111111";
    fu.SetContent(content);
}

void JsonTest()
{
    Json::Value root;
    std::string s;

    root["id"] = Json::Value(1);
    root["name"] = Json::Value("张三");
    root["sex"] = Json::Value("男");

    JsonUtil::Serialize(root, &s);
    std::cout << s << std::endl;

    Json::Value root2;
    JsonUtil::UnSerialize(s, &root2);
    std::cout << root2["id"] << std::endl;
    std::cout << root2["name"] << std::endl;
    std::cout << root2["sex"] << std::endl;
}

void DataTest()
{
    TableVideo tb_video;
    Json::Value video;
    // video["name"] = "加勒比海盗";
    // video["info"] = "讲述了17世纪的海盗杰克·斯帕罗充满危险的加勒比冒险之旅的故事";
    // video["video"] = "/video/pirate.ma4";
    // video["image"] = "/image/pirate.jpg";

    // video["name"] = "变形金刚";
    // video["info"] = "这是一个会变形的机器人，机器人大战，精彩纷呈~!";
    // video["video"] = "/video/robot.ma4";
    // video["image"] = "/image/robot.jpg";

    // tb_video.Insert(video);
    // tb_video.Update(2, video);
    // tb_video.SelectAll(&video);
    // tb_video.SelectOne(1, &video);
    tb_video.SelectLike("金刚", &video);
    std::string body;
    aod::JsonUtil::Serialize(video, &body);
    std::cout << body << std::endl;
    tb_video.Delete(2);
}

void ServerTest()
{
    aod::Server server(9090);
    server.RunModule();
}

int main()
{
    // FileUtilTest();
    // JsonTest();
    // DataTest();
    ServerTest();
    return 0;
}